package com.fireghost.jdt.database;

import java.sql.Timestamp;
import java.util.GregorianCalendar;
import java.util.Locale;

public class JobDbEntry {
	///////    Attributes    ///////
	private long iJobID;
	private String sJobDescription;
	private long iTimestampStart;
	private long iTimestampEnd;
	private long iTypeID;
	
	
	
	
	///////    Methods    ///////
	/***  Constructors  ***/
	public JobDbEntry(String p_sJobDescription, long p_iTimestampStart, long p_iTimestampEnd, long p_iTypeID) {
		iJobID = -1;
		sJobDescription = p_sJobDescription;
		iTimestampStart = p_iTimestampStart;
		iTimestampEnd = p_iTimestampEnd;
		iTypeID = p_iTypeID;
	}
	
	public JobDbEntry(String p_sJobDescription, long p_iTimestampStart) {
		
		iJobID = -1;
		sJobDescription = p_sJobDescription;
		iTimestampStart = p_iTimestampStart;
		iTimestampEnd = iTimestampStart;
		iTypeID = -1;
	}
	
	public JobDbEntry(long p_iJobID, String p_sJobDescription, long p_iTimestampStart, long p_iTimestampEnd, long p_iTypeID) {
		iJobID = p_iJobID;
		sJobDescription = p_sJobDescription;
		iTimestampStart = p_iTimestampStart;
		iTimestampEnd = p_iTimestampEnd;
		iTypeID = p_iTypeID;
	}
	
	
	/***  Getters  ***/
	public long getJobID() {
		return iJobID;
	}
	
	public String getJobDescription() {
		return sJobDescription;
	}
	
	public long getTimestampStart() {
		return iTimestampStart;
	}
	
	public long getTimestampEnd() {
		return iTimestampEnd;
	}
	
	public long getTypeID() {
		return iTypeID;
	}
	
	
	/***  Setters  ***/
	public void setJobID(long iJobID) {
		this.iJobID = iJobID;
	}

	public void setJobDescription(String sJobDescription) {
		this.sJobDescription = sJobDescription;
	}

	public void setTimestampStart(long iTimestampStart) {
		this.iTimestampStart = iTimestampStart;
	}

	public void setTimestampEnd(long iTimestampEnd) {
		this.iTimestampEnd = iTimestampEnd;
	}

	public void setTypeID(long iTypeID) {
		this.iTypeID = iTypeID;
	}
	
	
	/***  Others  ***/
	public String getStartEndString() {
		Timestamp oTimestampStart = new Timestamp(iTimestampStart);
		Timestamp oTimestampEnd = new Timestamp(iTimestampEnd);
		
		return oTimestampStart.getHours() +"h"+ oTimestampStart.getMinutes() +" - "+ oTimestampEnd.getHours() +"h"+ oTimestampEnd.getMinutes();
	}
	
	public String getFullDateString() {
		GregorianCalendar oCal = new GregorianCalendar();
		oCal.setTimeInMillis(iTimestampStart);
		
		String sDay = oCal.getDisplayName(GregorianCalendar.DAY_OF_WEEK, GregorianCalendar.LONG, Locale.getDefault());
		String sMonth = oCal.getDisplayName(GregorianCalendar.MONTH, GregorianCalendar.LONG, Locale.getDefault());
		
		return sDay +", "+ oCal.get(GregorianCalendar.DAY_OF_MONTH) +" "+ sMonth +" "+ oCal.get(GregorianCalendar.YEAR);
	}
	
	public String getWeekNumberString(String p_sLangWeekNo) {
		GregorianCalendar oCal = new GregorianCalendar();
		oCal.setTimeInMillis(iTimestampStart);
		
		return p_sLangWeekNo +" "+ oCal.get(GregorianCalendar.WEEK_OF_YEAR);
	}
	
	public String getStartEndTimeForJobViewString(String p_sLangFrom, String p_sLangTo) {
		Timestamp oTimestampStart = new Timestamp(iTimestampStart);
		Timestamp oTimestampEnd = new Timestamp(iTimestampEnd);
		
		String sStartTimeString = oTimestampStart.getHours() +"h"+ oTimestampStart.getMinutes();
		String sEndTimeString = oTimestampEnd.getHours() +"h"+ oTimestampEnd.getMinutes();
		
		return p_sLangFrom +" "+ sStartTimeString +" "+ p_sLangTo +" "+ sEndTimeString;
	}
	
	public String getTotalTimeString(String p_sLangTotal) {
		Timestamp oTimestampStart = new Timestamp(iTimestampStart);
		Timestamp oTimestampEnd = new Timestamp(iTimestampEnd);
		
		return p_sLangTotal +" "+ (oTimestampEnd.getHours() - oTimestampStart.getHours()) +"h"+ (oTimestampEnd.getMinutes() - oTimestampStart.getMinutes());
	}
}
